<template>
  <div class="certain">
    <header class="page-header">
      品类管理
    </header>
    <div class="btn-group">
      <el-button type="primary" @click="new_content">新增品类</el-button>
    </div>
    <el-table :data="content_list" border style="width: 100%">
      <el-table-column fixed prop="name" label="名字" width="300"> </el-table-column>
      <el-table-column prop="remark" label="描述"> </el-table-column>
      <el-table-column fixed="right" label="操作" width="300">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="del_content(scope.row.id, Math.abs(parseInt(scope.row.isdel) - 1))">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- <el-pagination class="page-pagination"
      background
      layout="prev, pager, next"
      :page-size="1"
      :total="certainData.length">
    </el-pagination> -->

    <el-dialog title="新增品类" :visible.sync="content_visible" :modal-append-to-body="false">
        <el-form :inline="true">
            <el-form-item label="名字">
                <el-input v-model="content_params.name"></el-input>
            </el-form-item>
            <el-form-item label="描述">
                <el-input v-model="content_params.remark"></el-input>
            </el-form-item>
             <el-form-item>
                <el-button type="success" @click="confirm_new_content()">确认添加</el-button>
            </el-form-item>
        </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: "certain",
  data() {
    return {
        content_params:{
            name: '',
            remark: ''
        },
        content_visible: false
    };
  },
  computed:{
    ...mapGetters({
      content_list: "content/content_list",
      total: "content/total",
    })
  },
  methods: {
    new_content() {
        this.content_visible = true
        this.content_params = {
            name: '',
            remark: ''
        }
    },
    del_content(id, isdel) {
        this.$store.dispatch('content/del_content', {id: id, isdel: isdel})
    },
    confirm_new_content() {
        this.$store.dispatch('content/create_content', this.content_params)
    }
  },
  created() {
      this.$store.commit('content/SET_VM', this)
      this.$store.dispatch('content/query_content')
  }
};
</script>

<style lang="scss">
.content{
    .btn-group {
        margin-top: 20px;
        margin-bottom: 20px;
        text-align: center;
    }
}
</style>


